package com.jams.rbac.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jams.common.core.system.JamsResponse;
import com.jams.rbac.api.entity.Tenant;
import com.jams.rbac.service.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 租户表
 *
 * @author linxb
 * @date 2020-01-07 19:23:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tenant")
@Api(value = "tenant", tags = "租户表管理")
public class TenantController {

    private final  TenantService tenantService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param tenant 租户表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public JamsResponse getTenantPage(Page page, Tenant tenant) {
        return JamsResponse.ok(tenantService.page(page, Wrappers.query(tenant)));
    }

    /**
     * 列表查询
     * @param tenant 租户表
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/list")
    public JamsResponse getTenantList(Tenant tenant) {
        return JamsResponse.ok(tenantService.list(Wrappers.query(tenant)));
    }

    /**
     * 通过id查询租户表
     * @param id id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public JamsResponse getById(@PathVariable("id") Long id) {
        return JamsResponse.ok(tenantService.getById(id));
    }

    /**
     * 新增租户表
     * @param tenant 租户表
     * @return JamsResponse
     */
    @ApiOperation(value = "新增租户表", notes = "新增租户表")
    @PostMapping
    public JamsResponse save(@RequestBody Tenant tenant) {
        return JamsResponse.ok(tenantService.save(tenant));
    }

    /**
     * 修改租户表
     * @param tenant 租户表
     * @return JamsResponse
     */
    @ApiOperation(value = "修改租户表", notes = "修改租户表")
    @PutMapping
    public JamsResponse updateById(@RequestBody Tenant tenant) {
        return JamsResponse.ok(tenantService.updateById(tenant));
    }

    /**
     * 通过id删除租户表
     * @param id id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id删除租户表", notes = "通过id删除租户表")
    @DeleteMapping("/{id}")
    public JamsResponse removeById(@PathVariable Long id) {
        return JamsResponse.ok(tenantService.removeById(id));
    }

}
